﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.Controllers.BackEnd;
using System.Web.Mvc;
using Proggy.Web.Cms.Core.PropertyTypes;
using Proggy.Web.Cms.Cache;

namespace Proggy.Web.Cms.Core.Controllers.PropertyType
{
    public class ProggyImagePickerController : BackEndControllerBase
    {
        /// <summary>
        /// Render proggyimage
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet, ChildActionOnly]
        public ActionResult RenderImage(ProggyImagePicker model)
        {
            // vars
            var src = string.Empty;
            var altTag = string.Empty;

            if (model.IsExternalImage)
            {
                src = model.ExternalUrl;
                altTag = model.ExternalAltTag;
            }
            else
            {
                // get url
                var url = UrlCache.GetUrlFromNodeId((int)model.InternalNodeId);

                // set
                src = url;
                altTag = model.InternalAltTag;
            }

            //
            //return Content("<img src=\"" + src + "\" alt=\"Site image - " + altTag + "\" />");
            return View();
        }
    }
}
